/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.shop.web.order;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.shop.entity.order.HkShopUserSubOrder;
import com.thinkgem.jeesite.modules.hk.shop.service.order.HkShopUserSubOrderService;

/**
 * 乐购用户子订单Controller
 * @author 罗天文
 * @version 2018-07-09
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/order/hkShopUserSubOrder")
public class HkShopUserSubOrderController extends BaseController {

	@Autowired
	private HkShopUserSubOrderService hkShopUserSubOrderService;
	
	@ModelAttribute
	public HkShopUserSubOrder get(@RequestParam(required=false) String id) {
		HkShopUserSubOrder entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkShopUserSubOrderService.get(id);
		}
		if (entity == null){
			entity = new HkShopUserSubOrder();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:order:hkShopUserSubOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkShopUserSubOrder hkShopUserSubOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkShopUserSubOrder> page = hkShopUserSubOrderService.findPage(new Page<HkShopUserSubOrder>(request, response), hkShopUserSubOrder); 
		model.addAttribute("page", page);
		return "hk/shop/order/hkShopUserSubOrderList";
	}

	@RequiresPermissions("shop:order:hkShopUserSubOrder:view")
	@RequestMapping(value = "form")
	public String form(HkShopUserSubOrder hkShopUserSubOrder, Model model) {
		model.addAttribute("hkShopUserSubOrder", hkShopUserSubOrder);
		return "hk/shop/order/hkShopUserSubOrderForm";
	}

	@RequiresPermissions("shop:order:hkShopUserSubOrder:edit")
	@RequestMapping(value = "save")
	public String save(HkShopUserSubOrder hkShopUserSubOrder, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkShopUserSubOrder)){
			return form(hkShopUserSubOrder, model);
		}
		hkShopUserSubOrderService.save(hkShopUserSubOrder);
		addMessage(redirectAttributes, "保存乐购用户子订单成功");
		return "redirect:"+Global.getAdminPath()+"/shop/order/hkShopUserSubOrder/?repage";
	}
	
	@RequiresPermissions("shop:order:hkShopUserSubOrder:edit")
	@RequestMapping(value = "delete")
	public String delete(HkShopUserSubOrder hkShopUserSubOrder, RedirectAttributes redirectAttributes) {
		hkShopUserSubOrderService.delete(hkShopUserSubOrder);
		addMessage(redirectAttributes, "删除乐购用户子订单成功");
		return "redirect:"+Global.getAdminPath()+"/shop/order/hkShopUserSubOrder/?repage";
	}

}